import {createAsyncThunk} from "@reduxjs/toolkit";
import {PagingData, PagingResult} from "type/Page";
import {SecurityMenu} from "type/entity/SecurityMenu";
import RequestHandler from "http/RequestHandler";

/** 请求菜单的分页数据 */
export const fetchMenuPageData = createAsyncThunk(
    'menu/fetchMenuPageData',
    async (paging: PagingData) => {
        return await RequestHandler.get<PagingResult<SecurityMenu>>("/manager/admin/menu/page/" + paging.page + "/" + paging.pageSize);
    }
);

/** 请求服务器更新菜单数据 */
export const fetchUpdateMenu = createAsyncThunk(
    'menu/fetchUpdateMenu',
    async (role: SecurityMenu) => {
        return await RequestHandler.post<number>("/manager/admin/menu", role);
    }
);

/** 请求服务器更新菜单数据 */
export const fetchAddMenu = createAsyncThunk(
    'menu/fetchAddMenu',
    async (role: SecurityMenu) => {
        return await RequestHandler.put<number>("/manager/admin/menu", role);
    }
);